const { post } = require('../model/http')
var request = require("request");

module.exports = async (ctx) => {
  // https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
  let token = '29_DPmQGPiYk6Ijcr_tuEsql2VB7HbB43fqPvRYRNapZEZffiaiU3oa5E6otrPI7KOFWC9TELFVWuPqT3hfBu6dWUnrfuBnMVMCs34B35wUJoiFUVInh4dM_ugjma8_quYK_nI-F-DlN5qINSC-OOYbACAZZJ';

  let url = `https://api.weixin.qq.com/cgi-bin/menu/create?access_token=${token}`;

  console.log(url);


  var btn = {
    "button": [{
      "type": "click",
      "name": "混合开发",
      "key": "V1001_TODAY_MUSIC"
    },
    {
      "name": "我的项目",
      "sub_button": [{
        "type": "view",
        "name": "猫眼电影",
        "url": "http://www.baidu.com/"
      },
      {
        "type": "click",
        "name": "菜谱大全",
        "url": "http://www.web678.xyz/"
      }
      ]
    }
    ]
  }

  request({
    timeout: 5000, // 设置超时
    method: 'POST', //请求方式
    url, //url
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    form: JSON.stringify(btn)
  }, function (error, response, body) {
    if (!error && response.statusCode == 200) {
      console.log('menu....')
      ctx.body = body;

    } else {
      ctx.body = 'error';
    }
  });
}